#include "droptimer.h"
#include "math.h"

DropTimer::DropTimer(QObject *_parent)
{
    connect(this, SIGNAL(timeout()), this, SLOT(inc()));
    this->setInterval(2000);
    this->setObjectName("droptimer");
    this->setParent(_parent);
    this->start();
}

// Move the helicopter side to side
void DropTimer::inc()
{
    DropPerson();
    int first = ((HelicopterForm*)(this->parent()))->dropLow;
    int second = ((HelicopterForm*)(this->parent()))->dropHigh;
    this->setInterval(rand() % second + first); // difficult level (on form)
}

// Drop a person out of the helicopter
void DropTimer::DropPerson()
{
    Person *pers = new Person(((HelicopterForm*)(this->parent())), (this->object->pos().x() + (this->object->width() / 2)), this->object->pos().y() + (this->object->height() / 2));
    pers->show();
}
